package Leetcode.链表;

/**
 * @Author kirito
 * @Date 2024/1/23 10:23
 * @PackageName:Leetcode.链表
 * @ClassName: 环形链表
 * @Description:
 * @Version 1.0
 */
public class 环形链表 {
    /**
     * 快慢指针
     * @param head
     * @return
     */
    public boolean hasCycle(ListNode head) {
        ListNode slow = head;
        ListNode fast = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (fast == slow) {
                return true;
            }
        }
        return false;
    }
}
